﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Palsta.Core.data
{
    class StringField : Field
    {
        private String value;

        public StringField(String v)
        {
            this.value = v;
        }
        override public String GetStringValue()
        {
            return value;
        }

        override public Boolean SetValue(String v)
        {
            this.value = v;
            return true;
        }

        override public FieldType GetFieldType()
        {
            return FieldType.String;
        }

        override public Boolean Equels(Field f)
        {
            if (f.GetFieldType() == FieldType.Boolean)
            {
                bool b = this.value.ToLower().Equals("true");
                return ((BooleanField)f).GetBooleanValue() == b;
            }
            else if (f.GetFieldType() == FieldType.String)
            {
                return this.value.Equals(f.GetStringValue());
            }
            return false;
        }

        override public Boolean NotEquels(Field f)
        {
            return !this.Equals(f);
        }


        override public Field Add(Field f)
        {
            StringField sf = new StringField(this.value + f.GetStringValue());
            return sf;
        }
    }
}
